package com.shujia.flink.tf

import com.shujia.flink.source.{MysqlSource, Student}
import org.apache.flink.streaming.api.scala._

object Demo5Agg {

  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val studentDS: DataStream[Student] = env.addSource(new MysqlSource)


    val keyBy: KeyedStream[Student, String] = studentDS.keyBy(_.clazz)


    /**
      * sum
      * max
      * maxBy
      * min
      * minBy
      *
      */

    /**
      * max 返回流中的最大值，但 maxBy 返回具有最大值的键， min 和 minBy 同理。
      *
      */

    val ds1: DataStream[Student] = keyBy.maxBy("age")


    ds1.print()


    env.execute()


  }

}
